# from django.contrib.auth.models import User
# from django.db import models

# Create your models here.
from django.db import models

from users.models import User


class IndexPage(models.Model):
    """新闻分类"""
    name = models.CharField(max_length=32,verbose_name='名称')

    class Meta:
        db_table = 'tb_goods_category'
        verbose_name = '头条首页'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class IndexDetails(models.Model):
    """新闻详情"""
    category = models.ForeignKey(IndexPage,on_delete=models.PROTECT,verbose_name='新闻类型')
    title = models.CharField(max_length=100,verbose_name='标题')
    abstract = models.CharField(max_length=400,verbose_name='摘要')
    create_time= models.DateTimeField(verbose_name='发布时间')
    content = models.TextField(verbose_name='正文')
    author = models.ForeignKey(User,on_delete=models.PROTECT,verbose_name='用户')

    class Meta:
        db_table = 'tb_news_details'
        verbose_name = '新闻详情'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s - %s' %(self.category_id,self.author_id)


class IndexComment(models.Model):
    """新闻评论"""
    news = models.ForeignKey(IndexPage,on_delete=models.PROTECT,verbose_name='新闻类型')
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='subs', null=True, blank=True,
                               verbose_name='新闻评论')
    author = models.ForeignKey(User,on_delete=models.PROTECT,verbose_name='用户')
    content = models.CharField(max_length=100,verbose_name='评论')
    create_time = models.DateTimeField(verbose_name='发布时间')

    class Meta:
        db_table = 'tb_news_comment'
        verbose_name = '新闻评论'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s - %s - %s' %(self.news_id,self.parent_id,self.author_id)

